'use strict';
const Conf = require('conf');
const pkg = require('../package.json');

const arl_old = new Set([
  '79437723c0024e17559a2f26b2d5023373506cdadd5e29dceda8c7b0aa03accaa40b4b17e8f8d21743edef40a2a16fca3511b5be4ca15c26c871082543c08893c0dd89f0d415378957e05179b3e7ec2c93625d5a8cf2d51a0d177de1a9833aff',
  'a338d78085d19cf4ff2b0020e57d5748c8c54634cd9535da6e7ba55e3332a1551d572f49f68a9e5c94801363a2b44a40c7b1ca8399de5fb732179d42c71161804ee7cd3b4801267038d02ccf28e62461c791929925ecdb135e208fdaf5a6caed',
  '9f0e26a319404f95e0323d86cdad9361fa66ca8a9218520e622338c75646f64c1d8a08d374478db795dc3fa1ec394853036019ec151b11668b677d8b32d8ffbfb16d4c083b247474ac84c83d0c7cdc5050a85be5e8dc9c49859f4e31cc2f131f'
]);
const arl =
  'a62f40421c53479e411c78cd7420f7e40e7de97ab9e6436558145bcedf4557bc79946e96c02d7fef9a3166024a11c4a501236eca892b1ef989267244153af6efc4fec75d47a776129e971a4c68cef0b33b1633baf0eb0e8c08e170224e9527fc';

const schema = {
  concurrency: {
    type: 'number',
    maximum: 99,
    minimum: 1,
    default: 4,
  },
  saveLayout: {
    type: 'object',
    default: {
      root: 'Music',
      playlistRoot: 'Playlist',
      path: '{ALB_ART_NAME} - {ALB_TITLE}',
      file: '{SNG_TITLE_VERSION}',
      trackNumber: true,
    },
  },
  albumCoverSize: {
    type: 'number',
    default: 1000,
  },
  cookies: {
    type: 'object',
    default: {
      arl,
    },
  },
};

const config = new Conf({
  schema,
  projectName: pkg.name,
  projectVersion: pkg.version,
  migrations: {
    '1.2.0': (store) => {
      store.set('albumCoverSize', 1000);
    },
    '1.3.1': (store) => {
      store.set('cookies', { arl });
    },
    '1.3.10': (store) => {
      const currentArl = store.get('cookies.arl');
      if (arl_old.has(currentArl)) {
        store.set('cookies.arl', arl);
      }
    },
  },
});

module.exports = config;
